package com.myworld.ucenter.service;

import com.myworld.framework.domain.ucenter.MyMenu;
import com.myworld.framework.domain.ucenter.MyUser;
import com.myworld.framework.domain.ucenter.ext.MyUserExt;
import com.myworld.ucenter.dao.MyUserRepository;
import com.myworld.ucenter.mapper.MyUserMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("myUserService")
public class MyUserService {
    @Autowired
    private MyUserMapper myUserMapper;

    @Autowired
    private MyUserRepository myUserRepository;



    //根据账号查询xcUser信息
    public MyUser findMyUserByUsername(String username){
        return myUserRepository.findByUsername(username);
    }

    /**
     * 根据用户的名称获取用户信息及相关权限
     * @param username
     * @return
     */
    public MyUserExt getUserExt(String username) {
        //根据用户账号查询MyUser信息
        MyUser myUser=this.findMyUserByUsername(username);
        if(myUser==null) return null;
        //用户id
        String userId=myUser.getId();
        //查询用户所拥有的权限
        List<MyMenu> myMeanList=myUserMapper.selectMeanByUserId(userId);
        MyUserExt myUserExt=new MyUserExt();
        BeanUtils.copyProperties(myUser,myUserExt);
        myUserExt.setMeans(myMeanList);
        return myUserExt;
    }
}
